package com.ofd.sign.service.impl;

import com.ofd.sign.domin.EcertLockSignReq;
import com.ofd.sign.domin.EcertSealReq;
import com.ofd.sign.domin.SignRes;
import com.ofd.sign.mode.ISignModeActuator;
import com.ofd.sign.service.SignService;
import com.ofd.sign.utils.AssertUtil;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 签章服务实现-具体业务由Mode实现，此处嵌套只为了特殊情况处理 或者异常处理
 *
 * @author wangrenjie
 */
@Slf4j
@Service
public class SignServiceImpl implements SignService {

    @Resource
    private Map<String, ISignModeActuator> signModeMap;

    /**
     * 签章
     *
     * @param req
     * @return
     */
    @Override
    public SignRes<Object> seal(EcertSealReq req) {
        val signModeActuator = signModeMap.get(req.getSignMode());
        AssertUtil.check(null == signModeActuator, "未找到签章模式执行器");
        val signRes = signModeActuator.seal(req);
        return signRes;
    }


    /**
     * 锁定签名
     *
     * @param req
     * @return
     */
    @Override
    public SignRes<Object> lockSign(EcertLockSignReq req) {
        val signModeActuator = signModeMap.get(req.getSignMode());
        AssertUtil.check(null == signModeActuator, "未找到签章模式执行器");
        val signRes = signModeActuator.lockSign(req);
        return signRes;
    }


}
